﻿// =================================================================== 
// 模块说明
//====================================================================
// 创建时间：2018-12-29 10:40:19
// 负责人：lvsc
// ===================================================================
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq.Expressions;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using OF.Utility;
using OF.Component.Model;
using OF.Component.IDAL;
using System.Text;
using OF.Component.DTO;

namespace OF.Component.DAL
{
	
	/// <summary>
	///网办订单审核记录 数据访问层
	/// </summary>	
	internal partial class NetworkOrderAudit
	{		
    
        /// <summary>
    	/// 根据断言条件获取单个网办订单审核记录
    	/// </summary>
        public NetworkOrderAuditInfo QuerySingle(Expression<Func<NetworkOrderAuditInfo, bool>> predicate)
	    {
            return SQLServerProvider.CreateObject(ConnectionStringKey, predicate);
        }
        
        /// <summary>
    	/// 根据断言条件获获取网办订单审核记录列表
    	/// </summary>
	    public IList<NetworkOrderAuditInfo> QueryList(Expression<Func<NetworkOrderAuditInfo, bool>> predicate)
	    {
	        return SQLServerProvider.CreateList(ConnectionStringKey, predicate);
	    }

        /// <summary>
        /// 根据城市或审批
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public List<NetworkOrderAuditInfo> GetListByOrder(long orderId)
        {
            List<NetworkOrderAuditInfo> list = new List<NetworkOrderAuditInfo>(); ;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT  * FROM [NetworkOrderAudit] ");
            strSql.Append("WHERE [OrderID]=@OrderID ");

            Database db = DatabaseFactory.CreateDatabase(this.ConnectionStringKey);
            DbCommand dbc = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbc, "@OrderID", DbType.Int64, orderId);
            using (IDataReader dr = db.ExecuteReader(dbc))
            {
                if (dr.Read())
                {
                    NetworkOrderAuditInfo info = GetByReader(dr);
                    list.Add(info);
                }
            }
            return list;
        }

        /// <summary>
        /// 根据订单查询操作记录
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public List<NetworkOrderAuditDto> GetListByOrderId(long orderId)
        {
            string sql = "SELECT r.*,t.UserName FROM NetworkOrderAudit r with(nolock) inner join GovUser t with(nolock) on r.CreateUserID = t.UserID where r.OrderID=@OrderID";
            List<NetworkOrderAuditDto> list = new List<NetworkOrderAuditDto>(); ;
            Database db = DatabaseFactory.CreateDatabase(this.ConnectionStringKey);
            DbCommand dbc = db.GetSqlStringCommand(sql);
            db.AddInParameter(dbc, "@OrderID", DbType.Int64, orderId);
            using (IDataReader dr = db.ExecuteReader(dbc))
            {
                if (dr.Read())
                {
                    NetworkOrderAuditDto info = SQLServerProvider.Create<NetworkOrderAuditDto>(dr);
                    list.Add(info);
                }
            }
            return list;
        }
    }
	
}